package sm.upgrade;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import sm.upgrade.api.UpgradePhase;
import sm.util.SMMap;

public class MySMUpgrade implements UpgradePhase {

	private static Logger logger = LoggerFactory.getLogger(UpgradePhase.class);

	private HibernateTemplate template;

	public void setTemplate(HibernateTemplate template) {
		this.template = template;
	}

	@Override
	public void upgrade() {
		logger.info("Start checking/updating MySM records.");

		// QCCR1E62339 delete 4 oob records for performance reason
		SMMap uimcompdefinitions = (SMMap) template.get("uimcompdefinitions",
				1011d);
		if (uimcompdefinitions != null) {
			template.delete("uimcompdefinitions", uimcompdefinitions);
		}
		uimcompdefinitions = (SMMap) template.get("uimcompdefinitions", 1014d);
		if (uimcompdefinitions != null) {
			template.delete("uimcompdefinitions", uimcompdefinitions);
		}

		SMMap uimcompdefcatscdefs = (SMMap) template.get("uimcompdefcatscdefs",
				1011d);
		if (uimcompdefcatscdefs != null) {
			template.delete("uimcompdefcatscdefs", uimcompdefcatscdefs);
		}
		uimcompdefcatscdefs = (SMMap) template
				.get("uimcompdefcatscdefs", 1014d);
		if (uimcompdefcatscdefs != null) {
			template.delete("uimcompdefcatscdefs", uimcompdefcatscdefs);
		}

		logger.info("  Finish checking/updating MySM records.");

	}

}
